/*
 * Copyright (C) 2010-2011 Comcast Cable.  All Rights Reserved.
 */
package com.hercules.android.receiver.model.events;

/**
 * <p>This is a subclass of XREEvent that represents the "onRPCReturn" event. It defines some properties specific to
 * this event. Note that values of all custom properties are actually stored in the XREEvent#params map.</p>
 *
 * <p><strong>Thread safety:</strong> This class is mutable and not thread safe.</p>
 *
 * @author saarixx, jmn
 * @version 1.0
 */
public class XREApplicationRPCReturnEvent extends XREApplicationEvent {

    /**
     * <p>Represents the name of the "on RPC return" event.<p>
     *
     * <p>This is a string constant used by the user when setting the name of the event.</p>
     */
    public static final String ON_RPC_RETURN_EVENT_NAME = "onRPCReturn";

    /**
     * <p>Represents the name used to retrieve the destination session GUID parameter.</p>
     */
    private static final String DESTINATION_SESSION_GUID = "destinationSessionGUID";

    /**
     * <p>Represents the name used to retrieve the source session GUID parameter.</p>
     */
    private static final String SOURCE_SESSION_GUID = "sourceSessionGUID";

    /**
     * <p>Represents the name used to retrieve the call GUID parameter.</p>
     */
    private static final String CALL_GUID = "callGUID";

    /**
     * <p>Represents the name used to retrieve the method parameter.</p>
     */
    private static final String METHOD = "method";

    /**
     * <p>Represents the name used to retrieve the return value parameter.</p>
     */
    private static final String RETURN_VAL = "returnVal";

    /**
     * <p>Creates new instance of {@link XREApplicationRPCCallEvent} class.</p>
     */
    public XREApplicationRPCReturnEvent() {
        // empty constructor
    }

    /**
     * <p>Retrieves the GUID of the application that was the recipient of the RPC call.</p>
     *
     * @return the GUID of the application that was the recipient of the RPC call
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public String getDestinationSessionGUID() {
        return getTypedParam(DESTINATION_SESSION_GUID, String.class);
    }

    /**
     * <p>Sets the GUID of the application that was the recipient of the RPC call.</p>
     *
     * @param destinationSessionGUID the GUID of the application that was the recipient of the RPC call
     *
     * @throws IllegalStateException if params is null
     */
    public void setDestinationSessionGUID(String destinationSessionGUID) {
        setParam(DESTINATION_SESSION_GUID, destinationSessionGUID);
    }

    /**
     * <p>Retrieves the GUID of the application that generated the RPC call.</p>
     *
     * @return the GUID of the application that generated the RPC call
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public String getSourceSessionGUID() {
        return getTypedParam(SOURCE_SESSION_GUID, String.class);
    }

    /**
     * <p>Sets the GUID of the application that generated the RPC call.</p>
     *
     * @param sourceSessionGUID the GUID of the application that generated the RPC call
     *
     * @throws IllegalStateException if params is null
     */
    public void setSourceSessionGUID(String sourceSessionGUID) {
        setParam(SOURCE_SESSION_GUID, sourceSessionGUID);
    }

    /**
     * <p>Retrieves the GUID that uniquely identifies the call.</p>
     *
     * @return the GUID that uniquely identifies the call
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public String getCallGUID() {
        return getTypedParam(CALL_GUID, String.class);
    }

    /**
     * <p>Sets the GUID that uniquely identifies the call.</p>
     *
     * @param callGUID the GUID that uniquely identifies the call
     *
     * @throws IllegalStateException if params is null
     */
    public void setCallGUID(String callGUID) {
        setParam(CALL_GUID, callGUID);
    }

    /**
     * <p>Retrieves the name of the method being called.</p>
     *
     * @return the name of the method being called
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public String getMethod() {
        return getTypedParam(METHOD, String.class);
    }

    /**
     * <p>Sets the name of the method being called.</p>
     *
     * @param method the name of the method being called
     *
     * @throws IllegalStateException if params is null
     */
    public void setMethod(String method) {
        setParam(METHOD, method);
    }

    /**
     * <p>Retrieves the result of the RPC function call.</p>
     *
     * @return the result of the RPC function call
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public Object getReturnVal() {
        return getTypedParam(RETURN_VAL, Object.class);
    }

    /**
     * <p>Sets the result of the RPC function call.</p>
     *
     * @param returnVal the result of the RPC function call
     *
     * @throws IllegalStateException if params is null
     */
    public void setReturnVal(Object returnVal) {
        setParam(RETURN_VAL, returnVal);
    }
}

